/*
 * �������� 2004-7-13
 *
 * ���������ļ�ģ��Ϊ
 * ���� > ��ѡ�� > Java > �������?> �����ע��?
 */
package com.dp.util;



import java.util.Enumeration;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;




public class DataLoader {
	
	private static Logger log = Logger.getLogger(DataLoader.class);
    /**
     *��
     * @param HttpServletRequest, HttpServletResponse, vUrl
     */
    public DataMap getPageData(HttpServletRequest request,
        HttpServletResponse response) {
        DataMap hm = new DataMap();
        Enumeration e = request.getParameterNames();

        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            String value = request.getParameter(name);

            log.debug(name+":"+value);
            value = BaseBean.ObjectToString(value);
            hm.put(name, value);
        }

        return hm;
    }

    public DataMap getPageData(HttpServletRequest request,
        HttpServletResponse response, String charset) {
        DataMap hm = new DataMap();

        try {
            Enumeration e = request.getParameterNames();

            while (e.hasMoreElements()) {
                String name = (String) e.nextElement();
                String value = request.getParameter(name);
                log.debug(name+":"+value);
                value = BaseBean.ObjectToString(value);
                value = new String(value.getBytes(charset));
                hm.put(name, value);
            }
        } catch (Exception e) {
            e.getMessage();
        }

        return hm;
    }
    public DataMap getMapData(Map<String,String> map) {
            DataMap hm = new DataMap();
//            Enumeration e = request.getParameterNames();

            if(!map.isEmpty())
            {
            	for(String strKey:map.keySet())
            	{
            		String name = strKey;
            		String value = map.get(strKey);
                    value = BaseBean.ObjectToString(value);
                    hm.put(name, value);            		
            	}
            }
            return hm;
    }
    
}
